package com.whw.fy.controller;

import com.whw.fy.entity.Message;
import com.whw.fy.entity.Parent;
import com.whw.fy.service.ParentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Api(tags = "家长模块")
@RestController
@RequestMapping("/api/parent")
public class ParentController {
    @Resource
    private ParentService parentService;

    @ApiOperation(value = "新增家长用户")
    @PostMapping("/one")
    public Message insert(Parent parent) throws ParseException {
        parent.setRegistrationTime(new Date());
        if (parent.getParentBirthtoString()!=null){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            parent.setParentBirth(simpleDateFormat.parse(parent.getParentBirthtoString()));
        }

        return parentService.insertSelective(parent);
    }


    @ApiOperation(value = "根据用户id删除家长用户")
    @DeleteMapping("/")
    public Message delete(Integer parentId) {
        return parentService.deleteByPrimaryKey(parentId);
    }

    @ApiOperation(value = "根据用户id修改家长用户信息")
    @PutMapping("/")
    public Message update(Parent parent) throws ParseException {
        return parentService.updateByPrimaryKeySelective(parent);
    }

    @ApiOperation(value = "根据家长用户id查询家长信息")
    @GetMapping("/id")
    public Message selectById(int id){
        return parentService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "家长姓名模糊搜索")
    @GetMapping("/mohuSearch/parentName")
    public Message MohuSearchByParentName(String parentName){
        return parentService.mohuSearchParentName(parentName);
    }

    @ApiOperation(value = "查询所有家长姓名<电话>")
    @GetMapping("/selectParentNameAndCall")
    public Message selectParentNameAndCall(){
        return parentService.selectParentNameAndCall();
    }

    @ApiOperation(value = "根据性别查询所有家长姓名<电话>")
    @GetMapping("/selectParentNameAndCallBySex")
    public Message selectParentNameAndCallBySex(String sex){
        return parentService.selectParentNameAndCallBySex(sex);
    }

    @ApiOperation(value = "根据性别查询所有家长")
    @GetMapping("/selectByParentSex")
    public Message selectByParentSex(String sex){
        return parentService.selectByParentSex(sex);
    }

    @ApiOperation(value = "查询所有")
    @GetMapping("/all")
    public Message selectAll(){
        return parentService.selectAll();
    }
}
